<?php
function excel_laporan($komponen_id){
	$_GET['nik_start'] = isset($_GET['nik_start']) ? sprintf('%07d',(int)$_GET['nik_start']) :'0000001'; 	
	$_GET['nik_end'] = isset($_GET['nik_end']) ? sprintf('%07d',(int)$_GET['nik_end']) :'9999999'; 	
 $periode_id = isset($_GET['periode_id']) ? $_GET['periode_id'] : 0; 

	$header = array(
		'No'=>array('style'=>'border-bottom:2px solid;width:5%'),  
		'NIK'=>array('style'=>'border-bottom:2px solid;width:10%'),  
		'Name'=>array('style'=>'border-bottom:2px solid;width:50%'),  
		'Jumlah'=>array('style'=>'text-align:right;border-bottom:2px solid;width:30%'),   
	);  
	$query = "
		SELECT a.karyawan_id, b.kalkulasi FROM  karyawan a  
		INNER JOIN pr_gaji_komponen b ON b.karyawan_id = a.karyawan_id	
		AND b.periode_id=". $periode_id ." 
		AND b.kalkulasi <> 0
		AND b.komponen_id=".$komponen_id;
	if($_GET['nik_start'] <> '' && $_GET['nik_end'] <> ''){
		$query .=" AND ( a.nik BETWEEN {$_GET['nik_start']} AND {$_GET['nik_end']} ) ";
	}		
	$query .="	ORDER BY a.nik"; 	
	
	$result = my_query($query);
	while($ey = my_fetch_array($result )){
		$karyawan =  loaddata_karyawan($ey['karyawan_id']);  
		if((int) $ey['kalkulasi'] == 0)continue;
		$i++;
		$row[] = array(
			'#'=> $i, 
			'nik'=>  '\''.sprintf('%07d',$karyawan['nik']) ,
			'nama'=>  $karyawan['nama_gelar'] ,
			'jumlah'=>    $ey['kalkulasi'] 
		);
	}
	
	
	$datas = table_rows_excel($row); 
	return table_builder_excel($header , $datas , 4 ,false ); 
		
}


function list_laporan($komponen_id){
	if($komponen_id==0)return list_thp( );
	elseif($komponen_id==1000)return list_gapok( );
	$_GET['nik_start'] = isset($_GET['nik_start']) ? sprintf('%07d',(int)$_GET['nik_start']) :'0000001'; 	
	$_GET['nik_end'] = isset($_GET['nik_end']) ? sprintf('%07d',(int)$_GET['nik_end']) :'9999999'; 	
	$periode_id = isset($_GET['periode_id']) ? $_GET['periode_id'] : 0; 
	$header = array(
		'No'=>array('style'=>'border-bottom:2px solid;width:5%'),  
		'NIK'=>array('style'=>'border-bottom:2px solid;width:10%'),  
		'Name'=>array('style'=>'border-bottom:2px solid;width:50%'),  
		'Jumlah'=>array('style'=>'text-align:right;border-bottom:2px solid;width:30%'),  
	//	'Total'=>array('style'=>'text-align:right;border-bottom:2px solid;width:20%'),  
	);
	
	 
		$query = "
			SELECT a.karyawan_id, b.kalkulasi FROM  karyawan a  
			INNER JOIN pr_gaji_komponen b ON b.karyawan_id = a.karyawan_id	
			AND b.periode_id=".$periode_id ." 
			AND b.kalkulasi <> 0
			AND b.komponen_id=".$komponen_id;
		if($_GET['nik_start'] <> '' && $_GET['nik_end'] <> ''){
			$query .=" AND ( a.nik BETWEEN '{$_GET['nik_start']}' AND '{$_GET['nik_end']}' ) ";
		}		
		$query .="	ORDER BY a.nik"; 	 
	$result = my_query($query );
	$total_records = my_num_rows($result );
	$scroll_page =5;  
	$per_page =35;  
	$current_page = isset($_GET['page']) ? (int) $_GET['page'] : 1 ; 
	if($current_page < 1){
		$current_page = 1;
	}		 
	$pager_url  ="index.php?periode_id={$_GET['periode_id']}&com={$_GET['com']}&komponen_id={$komponen_id}&task=9&nik_start={$_GET['nik_start']}&nik_end={$_GET['nik_end']}&page=";	 
	$inactive_page_tag = 'style="padding:4px;background-color:#BBBBBB"';  
	$previous_page_text = ' Mundur '; 
	$next_page_text = ' Maju ';  
	$first_page_text = ' Awal '; 
	$last_page_text = ' Akhir ';
	
	$kgPagerOBJ = new kgPager();
	$kgPagerOBJ->pager_set(
		$pager_url, 
		$total_records, 
		$scroll_page, 
		$per_page, 
		$current_page, 
		$inactive_page_tag, 
		$previous_page_text, 
		$next_page_text, 
		$first_page_text, 
		$last_page_text ,$pager_url_last); 
	 		
	$result = my_query($query ." LIMIT ".$kgPagerOBJ->start.", ".$kgPagerOBJ->per_page); 	
	$row = array(); 
	$i = ($current_page  - 1 ) * 35; 
	$total=0 ;

	while($ey = my_fetch_array($result )){
		$karyawan =  loaddata_karyawan($ey['karyawan_id']); 
		if((int) $ey['kalkulasi'] == 0)continue;		
		$i++;
		$row[] = array(
			'#'=>position_text_align($i,'center'),
			'nik'=>  $karyawan['nik'] ,
			'nama'=>  $karyawan['nama_gelar'] ,
			'jumlah'=>  position_text_align (rp_format($ey['kalkulasi']) ,'right'),   
	//		'total'=>  position_text_align (rp_format($total) ,'right'),   
		);
	}
	
	$datas = table_rows($row); 
	$paging = $kgPagerOBJ ->showPaging();
	$view = form_header( "ujisubmit" , "ujisubmit"  );
	$sks=my_get_data_by_id('pr_komponen_gaji','komponen_gaji_id',$komponen_id);
	
	
	$query_check_periode = " SELECT * FROM pr_periode ORDER BY periode_id DESC";
	$result = my_query($query_check_periode);
	$prs = array();
	while($prow = my_fetch_array($result)){
		$prs[$prow['periode_id']] = date('Y-m',strtotime($prow['tanggal']));
	}
	$fperiode_id = array(
		'id'=>'periode_id',
		'value'=>$periode_id ,
		'name'=>'periode_id',
	);
	$view .= form_field_display( form_dropdown($fperiode_id,$prs)   , "Periode Gaji"   );
	
	$nik_start = isset($_GET['nik_start']) ? $_GET['nik_start'] : $nik_start_default;
	$nik_end = isset($_GET['nik_end']) ? $_GET['nik_end'] : $nik_end_default;
	$form_start = '<input type="text" size="7" value="'.$nik_start.'" name="nik_start" />';
	$form_end = '<input type="text" size="7" value="'.$nik_end.'" name="nik_end" />';
	$view .= '<input type="hidden"  value="'.$_GET['com'].'" name="com" />';
	$view .= form_field_display( $form_start.' s/d '.$form_end  , "NIK Range"   );
	$komps = array();
	$query = "SELECT komponen_gaji_id , nama_komponen_gaji FROM pr_komponen_gaji ORDER BY tipe ASC , komponen_gaji_id ASC";
	$res = my_query($query);
	while($klrow = my_fetch_array($res)){
		$komps[$klrow['komponen_gaji_id']] = $klrow['nama_komponen_gaji'];
	}
	$komps[0] = '** Take home pay **';
	$komps[1000] = '** Gaji dibayar **';
 
	$fs = array(
		'id'=>'komponen_id',
		'value'=>$komponen_id ,
		'name'=>'komponen_id',
		'onchange'=>'javascript:document.ujisubmit.submit();'
	);
	$view .= form_field_display( form_dropdown($fs,$komps)   , "Komponen Gaji"   );
	
		$submit = array(
		'value' => (  ' Check '  ),
		'name' => 'simpan', 
		'type'=>'submit','class'=>'main_button'
	);
	$form_submit= form_dynamic($submit); 	
	$cetak = array(
		'value' => (  ' Cetak '  ),
		'onclick' => 'javascript:location.href=\'index.php?com='.$_GET['com'].'&periode_id='.$periode_id.'&task=cetak_report_komponen_gaji&komponen_id='.$komponen_id.'&nik_start='.$_GET['nik_start'].'&nik_end='.$_GET['nik_end'].'\'', 
		//'onclick' => 'javascript:location.href=\'index.php?com=report&periode_id='.$periode_id.'&task=txt_komponen_gaji&komponen_id='.$komponen_id.'&nik_start='.$_GET['nik_start'].'&nik_end='.$_GET['nik_end'].'\'', 
		'type'=>'button','class'=>'main_button'
	);
	$form_cetak= form_dynamic($cetak); 	
 
	$excel = array(
		'value' => (  ' Excel '  ),
		'onclick' => 'javascript:location.href=\'index.php?com='.$_GET['com'].'&periode_id='.$periode_id.'&task=excel_report_komponen_gaji&komponen_id='.$komponen_id.'&nik_start='.$_GET['nik_start'].'&nik_end='.$_GET['nik_end'].'\'', 
		'type'=>'button','class'=>'main_button'
	);
	$form_excel= form_dynamic($excel); 
	
	$view .= form_field_display(    $form_cetak .' '.  $form_excel , "&nbsp;" ,  "" );
	$view .= form_footer( );
	$view = str_replace("method=\"post\"","method=\"get\"",$view);
	$search = '<form method="GET"><input type="hidden" name="com" value="'.$_GET['com'].'" />
	<span style="font:10px verdana"><b>Pencarian cepat</b></span>
	<br/><input type="text"  style="width:200px;" name="key" value="'.(isset($_GET['key']) ? $_GET['key']: "").'" />
	<input class="simple_search" type="submit" value=" CARI " /> </form>';
	$printmenu = additional_menu_on_list( array(), '');
	return $view.$printmenu .table_builder($header , $datas ,  15 ,false , $paging  );
} 

function list_thp( ){
	
	$_GET['nik_start'] = isset($_GET['nik_start']) ? sprintf('%07d',(int)$_GET['nik_start']) :'0000001'; 	
	$_GET['nik_end'] = isset($_GET['nik_end']) ? sprintf('%07d',(int)$_GET['nik_end']) :'9999999'; 	
 $periode_id = isset($_GET['periode_id']) ? $_GET['periode_id'] : 0; 
	
	$header = array(
		'No'=>array('style'=>'border-bottom:2px solid;width:5%'),  
		'NIK'=>array('style'=>'border-bottom:2px solid;width:10%'),  
		'Name'=>array('style'=>'border-bottom:2px solid;width:50%'),  
		'Jumlah'=>array('style'=>'text-align:right;border-bottom:2px solid;width:30%'),  
	//	'Total'=>array('style'=>'text-align:right;border-bottom:2px solid;width:20%'),  
	);
	
	$header = array(
		'No'=>array('style'=>'border-bottom:2px solid;width:5%'),  
		'NIK'=>array('style'=>'border-bottom:2px solid;width:20%'),  
		'Name'=>array('style'=>'border-bottom:2px solid;width:40%'),  
	//	'No. Account'=>array('style'=>'border-bottom:2px solid;width:15%'),  
		'Amount'=>array('style'=>'text-align:right;border-bottom:2px solid;width:20%'),  
	);
	
 
		$query = "   select a.karyawan_id FROM pr_gaji a INNER JOIN karyawan b ON a.karyawan_id = b.karyawan_id
		 WHERE a.periode_id={$periode_id}  ";
		if($_GET['nik_start'] <> '' && $_GET['nik_end'] <> ''){
			$query .=" AND ( b.nik BETWEEN {$_GET['nik_start']} AND {$_GET['nik_end']} ) ";
		}
	 	$query .="  ORDER BY b.nik ASC ";
	$result = my_query($query );
	$total_records = my_num_rows($result );
	$scroll_page =5;  
	$per_page =35;  
	$current_page = isset($_GET['page']) ? (int) $_GET['page'] : 1 ; 
	if($current_page < 1){
		$current_page = 1;
	}		 
	$pager_url  ="index.php?com={$_GET['com']}&periode_id={$periode_id}&komponen_id=0&task=9&nik_start={$_GET['nik_start']}&nik_end={$_GET['nik_end']}&page=";	 
	$inactive_page_tag = 'style="padding:4px;background-color:#BBBBBB"';  
	$previous_page_text = ' Mundur '; 
	$next_page_text = ' Maju ';  
	$first_page_text = ' Awal '; 
	$last_page_text = ' Akhir ';
	
	$kgPagerOBJ = new kgPager();
	$kgPagerOBJ->pager_set(
		$pager_url, 
		$total_records, 
		$scroll_page, 
		$per_page, 
		$current_page, 
		$inactive_page_tag, 
		$previous_page_text, 
		$next_page_text, 
		$first_page_text, 
		$last_page_text ,$pager_url_last); 
	 		
	$result = my_query($query ." LIMIT ".$kgPagerOBJ->start.", ".$kgPagerOBJ->per_page); 	
	$row = array(); 
	$i = ($current_page  - 1 ) * 35; 
	while($ey = my_fetch_array($result )){
		$i++;
		$karyawan =  loaddata_karyawan($ey['karyawan_id']);  
		$jabatan =  loaddata_jabatan($karyawan['jabatan_id']);  
		$query = " SELECT takehomepay FROM pr_gaji 
			WHERE periode_id=".$periode_id."
			AND karyawan_id=".$ey['karyawan_id']
		;
		$result1 = my_query($query);	
		$gajis = my_fetch_array($result1);
		if(	$gajis ){
			$row[] = array(
				'#'=>position_text_align($i,'center'),
				'nik'=>  $karyawan['nik'] ,
				'nama'=>  $karyawan['nama_gelar'] ,
		//		'norek'=>  $karyawan['norek'] ,
				'amount'=>  position_text_align (rp_format($gajis['takehomepay']) ,'right'),   
			);
		}		

	}
	
	$datas = table_rows($row); 
	$paging = $kgPagerOBJ ->showPaging();
	$view = form_header( "ujisubmit" , "ujisubmit"  );
	//$sks=my_get_data_by_id('pr_komponen_gaji','komponen_gaji_id',$komponen_id);
	$query_check_periode = " SELECT * FROM pr_periode ORDER BY periode_id DESC";
	$result = my_query($query_check_periode);
	$prs = array();
	while($prow = my_fetch_array($result)){
		$prs[$prow['periode_id']] = date('Y-m',strtotime($prow['tanggal']));
	}
	$fperiode_id = array(
		'id'=>'periode_id',
		'value'=>$periode_id ,
		'name'=>'periode_id',
	);
	$view .= form_field_display( form_dropdown($fperiode_id,$prs)   , "Periode Gaji"   );
	
	 
	$nik_start = isset($_GET['nik_start']) ? $_GET['nik_start'] : $nik_start_default;
	$nik_end = isset($_GET['nik_end']) ? $_GET['nik_end'] : $nik_end_default;
	$form_start = '<input type="text" size="7" value="'.$nik_start.'" name="nik_start" />';
	$form_end = '<input type="text" size="7" value="'.$nik_end.'" name="nik_end" />';
	$view .= '<input type="hidden"  value="'.$_GET['com'].'" name="com" />';
	$view .= form_field_display( $form_start.' s/d '.$form_end  , "NIK Range"   );
	
	$komps = array();
	$query = "SELECT komponen_gaji_id , nama_komponen_gaji FROM pr_komponen_gaji ORDER BY tipe ASC , komponen_gaji_id ASC";
	$res = my_query($query);
	while($klrow = my_fetch_array($res)){
		$komps[$klrow['komponen_gaji_id']] = $klrow['nama_komponen_gaji'];
	}
	$komps[0] = '** Take home pay **';
	$komps[1000] = '** Gaji dibayar **';
	$fs = array(
		'id'=>'komponen_id',
		'value'=>$komponen_id ,
		'name'=>'komponen_id',
	
		'onchange'=>'javascript:document.ujisubmit.submit();'
	);
	$view .= form_field_display( form_dropdown($fs,$komps)   , "Komponen Gaji"   );
		$submit = array(
		'value' => (  ' Check '  ),
		'name' => 'simpan', 
		'type'=>'submit','class'=>'main_button'
	);
	$form_submit= form_dynamic($submit); 	
	$cetak = array(
		'value' => (  ' Cetak '  ),
		'onclick' => 'javascript:location.href=\'index.php?com='.$_GET['com'].'&periode_id='.$periode_id.'&task=cetak_report_komponen_gaji&komponen_id=0&nik_start='.$_GET['nik_start'].'&nik_end='.$_GET['nik_end'].'\'', 
		//'onclick' => 'javascript:location.href=\'index.php?com=report&periode_id='.$periode_id.'&task=txt_komponen_gaji&komponen_id='.$komponen_id.'&nik_start='.$_GET['nik_start'].'&nik_end='.$_GET['nik_end'].'\'', 
		'type'=>'button','class'=>'main_button'
	);
	$form_cetak= form_dynamic($cetak); 	
	$excel = array(
		'value' => (  ' Excel '  ),
		'onclick' => 'javascript:location.href=\'index.php?com='.$_GET['com'].'&periode_id='.$periode_id.'&task=excel_report_komponen_gaji&komponen_id='.$komponen_id.'&nik_start='.$_GET['nik_start'].'&nik_end='.$_GET['nik_end'].'\'', 
		'type'=>'button','class'=>'main_button'
	);
	$form_excel= form_dynamic($excel); 
	
	$view .= form_field_display(  $form_cetak .' '.$form_excel , "&nbsp;" ,  "" );
	 $view .= form_footer( );
	$view = str_replace("method=\"post\"","method=\"get\"",$view);
	$search = '<form method="GET"><input type="hidden" name="com" value="'.$_GET['com'].'" />
	<span style="font:10px verdana"><b>Pencarian cepat</b></span>
	<br/><input type="text"  style="width:200px;" name="key" value="'.(isset($_GET['key']) ? $_GET['key']: "").'" />
	<input class="simple_search" type="submit" value=" CARI " /> </form>';
	$printmenu = additional_menu_on_list( array(), '');
	return $view.$printmenu .table_builder($header , $datas ,  15 ,false , $paging  );
} 
function list_gapok( ){
	
	$_GET['nik_start'] = isset($_GET['nik_start']) ? sprintf('%07d',(int)$_GET['nik_start']) :'0000001'; 	
	$_GET['nik_end'] = isset($_GET['nik_end']) ? sprintf('%07d',(int)$_GET['nik_end']) :'9999999'; 	
 $periode_id = isset($_GET['periode_id']) ? $_GET['periode_id'] : 0; 
	
	$header = array(
		'No'=>array('style'=>'border-bottom:2px solid;width:5%'),  
		'NIK'=>array('style'=>'border-bottom:2px solid;width:10%'),  
		'Name'=>array('style'=>'border-bottom:2px solid;width:50%'),  
		'Jumlah'=>array('style'=>'text-align:right;border-bottom:2px solid;width:30%'),  
	//	'Total'=>array('style'=>'text-align:right;border-bottom:2px solid;width:20%'),  
	);
	
	$header = array(
		'No'=>array('style'=>'border-bottom:2px solid;width:5%'),  
		'NIK'=>array('style'=>'border-bottom:2px solid;width:20%'),  
		'Name'=>array('style'=>'border-bottom:2px solid;width:40%'),  
	//	'No. Account'=>array('style'=>'border-bottom:2px solid;width:15%'),  
		'Amount'=>array('style'=>'text-align:right;border-bottom:2px solid;width:20%'),  
	);
	
	 
		$query = "   select a.karyawan_id FROM pr_gaji a INNER JOIN karyawan b ON a.karyawan_id = b.karyawan_id
		 WHERE a.periode_id={$periode_id}  ";
		if($_GET['nik_start'] <> '' && $_GET['nik_end'] <> ''){
			$query .=" AND ( b.nik BETWEEN {$_GET['nik_start']} AND {$_GET['nik_end']} ) ";
		}
	 	$query .="  ORDER BY b.nik ASC ";
	$result = my_query($query );
	$total_records = my_num_rows($result );
	$scroll_page =5;  
	$per_page =35;  
	$current_page = isset($_GET['page']) ? (int) $_GET['page'] : 1 ; 
	if($current_page < 1){
		$current_page = 1;
	}		 
	$pager_url  ="index.php?com={$_GET['com']}&periode_id={$periode_id}&komponen_id=1000&task=9&nik_start={$_GET['nik_start']}&nik_end={$_GET['nik_end']}&page=";	 
	$inactive_page_tag = 'style="padding:4px;background-color:#BBBBBB"';  
	$previous_page_text = ' Mundur '; 
	$next_page_text = ' Maju ';  
	$first_page_text = ' Awal '; 
	$last_page_text = ' Akhir ';
	
	$kgPagerOBJ = new kgPager();
	$kgPagerOBJ->pager_set(
		$pager_url, 
		$total_records, 
		$scroll_page, 
		$per_page, 
		$current_page, 
		$inactive_page_tag, 
		$previous_page_text, 
		$next_page_text, 
		$first_page_text, 
		$last_page_text ,$pager_url_last); 
	 		
	$result = my_query($query ." LIMIT ".$kgPagerOBJ->start.", ".$kgPagerOBJ->per_page); 	
	$row = array(); 
	$i = ($current_page  - 1 ) * 35; 
	while($ey = my_fetch_array($result )){
		$i++;
		$karyawan =  loaddata_karyawan($ey['karyawan_id']);  
		$jabatan =  loaddata_jabatan($karyawan['jabatan_id']);  
		$query = " SELECT gaji_dibayar FROM pr_gaji 
			WHERE periode_id=".$periode_id."
			AND karyawan_id=".$ey['karyawan_id']
		;
		$result1 = my_query($query);	
		$gajis = my_fetch_array($result1);
		///if(	$gajis ){
			$row[] = array(
				'#'=>position_text_align($i,'center'),
				'nik'=>  $karyawan['nik'] ,
				'nama'=>  $karyawan['nama_gelar'] ,
		//		'norek'=>  $karyawan['norek'] ,
				'amount'=>  position_text_align (rp_format($gajis['gaji_dibayar']) ,'right'),   
			);
		//}		

	}
	
	$datas = table_rows($row); 
	$paging = $kgPagerOBJ ->showPaging();
	$view = form_header( "ujisubmit" , "ujisubmit"  );
	//$sks=my_get_data_by_id('pr_komponen_gaji','komponen_gaji_id',$komponen_id);
	$query_check_periode = " SELECT * FROM pr_periode ORDER BY periode_id DESC";
	$result = my_query($query_check_periode);
	$prs = array();
	while($prow = my_fetch_array($result)){
		$prs[$prow['periode_id']] = date('Y-m',strtotime($prow['tanggal']));
	}
	$fperiode_id = array(
		'id'=>'periode_id',
		'value'=>$periode_id ,
		'name'=>'periode_id',
	);
	$view .= form_field_display( form_dropdown($fperiode_id,$prs)   , "Periode Gaji"   );
	
	 
	$nik_start = isset($_GET['nik_start']) ? $_GET['nik_start'] : $nik_start_default;
	$nik_end = isset($_GET['nik_end']) ? $_GET['nik_end'] : $nik_end_default;
	$form_start = '<input type="text" size="7" value="'.$nik_start.'" name="nik_start" />';
	$form_end = '<input type="text" size="7" value="'.$nik_end.'" name="nik_end" />';
	$view .= '<input type="hidden"  value="'.$_GET['com'].'" name="com" />';
	$view .= form_field_display( $form_start.' s/d '.$form_end  , "NIK Range"   );
	
	$komps = array();
	$query = "SELECT komponen_gaji_id , nama_komponen_gaji FROM pr_komponen_gaji ORDER BY tipe ASC , komponen_gaji_id ASC";
	$res = my_query($query);
	while($klrow = my_fetch_array($res)){
		$komps[$klrow['komponen_gaji_id']] = $klrow['nama_komponen_gaji'];
	}
	$komps[0] = '** Take home pay **';
	$komps[1000] = '** Gaji dibayar **';
	$fs = array(
		'id'=>'komponen_id',
		'value'=>1000,
		'name'=>'komponen_id',
		'onchange'=>'javascript:document.ujisubmit.submit();'
	);
	$view .= form_field_display( form_dropdown($fs,$komps)   , "Komponen Gaji"   );
		$submit = array(
		'value' => (  ' Check '  ),
		'name' => 'simpan', 
		'type'=>'submit','class'=>'main_button'
	);
	$form_submit= form_dynamic($submit); 	
	$cetak = array(
		'value' => (  ' Cetak '  ),
		'onclick' => 'javascript:location.href=\'index.php?com='.$_GET['com'].'&periode_id='.$periode_id.'&task=cetak_report_komponen_gaji&komponen_id='.$_GET['komponen_id'].'&nik_start='.$_GET['nik_start'].'&nik_end='.$_GET['nik_end'].'\'', 
		//'onclick' => 'javascript:location.href=\'index.php?com=report&periode_id='.$periode_id.'&task=txt_komponen_gaji&komponen_id='.$_GET['komponen_id'].'&nik_start='.$_GET['nik_start'].'&nik_end='.$_GET['nik_end'].'\'', 
		'type'=>'button','class'=>'main_button'
	);
	$form_cetak= form_dynamic($cetak); 	
	$excel = array(
		'value' => (  ' Excel '  ),
		'onclick' => 'javascript:location.href=\'index.php?com='.$_GET['com'].'&periode_id='.$periode_id.'&task=excel_report_komponen_gaji&komponen_id=1000&nik_start='.$_GET['nik_start'].'&nik_end='.$_GET['nik_end'].'\'', 
		'type'=>'button','class'=>'main_button'
	);
	$form_excel= form_dynamic($excel); 
	
	$view .= form_field_display(  $form_cetak .' '.$form_excel , "&nbsp;" ,  "" );
	 $view .= form_footer( );
	$view = str_replace("method=\"post\"","method=\"get\"",$view);
	$search = '<form method="GET"><input type="hidden" name="com" value="'.$_GET['com'].'" />
	<span style="font:10px verdana"><b>Pencarian cepat</b></span>
	<br/><input type="text"  style="width:200px;" name="key" value="'.(isset($_GET['key']) ? $_GET['key']: "").'" />
	<input class="simple_search" type="submit" value=" CARI " /> </form>';
	$printmenu = additional_menu_on_list( array(), '');
	return $view.$printmenu .table_builder($header , $datas ,  15 ,false , $paging  );
} 

function xl_list_of_transfer(){
	$header = array(
		'No'=>array('style'=>'border-bottom:2px solid;width:5%'),  
		'NIK'=>array('style'=>'border-bottom:2px solid;width:20%'),  
		'Name'=>array('style'=>'border-bottom:2px solid;width:40%'),  
	//	'No. Account'=>array('style'=>'border-bottom:2px solid;width:15%'),  
		'Amount'=>array('style'=>'text-align:right;border-bottom:2px solid;width:20%'),  
	);
	$_GET['nik_start'] = isset($_GET['nik_start']) ? sprintf('%07d',(int)$_GET['nik_start']) :'0000001'; 	
	$_GET['nik_end'] = isset($_GET['nik_end']) ? sprintf('%07d',(int)$_GET['nik_end']) :'9999999'; 	
 $periode_id = isset($_GET['periode_id']) ? $_GET['periode_id'] : 0; 
	
		$query = "   select a.karyawan_id FROM pr_gaji a INNER JOIN karyawan b ON a.karyawan_id = b.karyawan_id
		 WHERE a.periode_id={$periode_id}  ";
		if($_GET['nik_start'] <> '' && $_GET['nik_end'] <> ''){
			$query .=" AND ( b.nik BETWEEN {$_GET['nik_start']} AND {$_GET['nik_end']} ) ";
		}
	 	$query .="  ORDER BY b.nik ASC ";
	$result = my_query($query);
	while($ey = my_fetch_array($result )){
		$i++;
		$karyawan =  loaddata_karyawan($ey['karyawan_id']);  
		$jabatan =  loaddata_jabatan($karyawan['jabatan_id']);  
		$query = " SELECT gaji_dibayar ,takehomepay FROM pr_gaji 
			WHERE periode_id=".$periode_id."
			AND karyawan_id=".$ey['karyawan_id']
		;
		$result1 = my_query($query);	
		$gajis = my_fetch_array($result1);
		if(	$gajis ){
			$row[] = array(
				'#'=>position_text_align($i,'center'),
				'nik'=>  '\'' .sprintf('%07d',$karyawan['nik']) ,
				'nama'=>  $karyawan['nama_gelar'] ,
			//	'norek'=>  $karyawan['norek'] ,
				'amount'=>  $gajis['takehomepay'] 
			);
		}		

	}
	
	$datas = table_rows_excel($row); 
	return table_builder_excel($header , $datas , 6 ,false ); 
}

function xl_list_of_gapok(){
	$header = array(
		'No'=>array('style'=>'border-bottom:2px solid;width:5%'),  
		'NIK'=>array('style'=>'border-bottom:2px solid;width:20%'),  
		'Name'=>array('style'=>'border-bottom:2px solid;width:40%'),  
	//	'No. Account'=>array('style'=>'border-bottom:2px solid;width:15%'),  
		'Amount'=>array('style'=>'text-align:right;border-bottom:2px solid;width:20%'),  
	);
	$_GET['nik_start'] = isset($_GET['nik_start']) ? sprintf('%07d',(int)$_GET['nik_start']) :'0000001'; 	
	$_GET['nik_end'] = isset($_GET['nik_end']) ? sprintf('%07d',(int)$_GET['nik_end']) :'9999999'; 	
 $periode_id = isset($_GET['periode_id']) ? $_GET['periode_id'] : 0; 
	
		$query = "
			SELECT * FROM karyawan a 
			WHERE a.karyawan_id NOT IN (select karyawan_id FROM karyawan_disable)
			AND a.karyawan_id NOT IN (select karyawan_id FROM pemberhentian) 		
		";
		if($_GET['nik_start'] <> '' && $_GET['nik_end'] <> ''){
			$query .=" AND ( a.nik BETWEEN {$_GET['nik_start']} AND {$_GET['nik_end']} ) ";
		}	
		 	$query .=" ORDER BY a.nik ASC ";
	$result = my_query($query);
	while($ey = my_fetch_array($result )){
		$i++;
		$karyawan =  loaddata_karyawan($ey['karyawan_id']);  
		$jabatan =  loaddata_jabatan($karyawan['jabatan_id']);  
		$query = " SELECT gaji_dibayar   FROM pr_gaji 
			WHERE periode_id=".$periode_id."
			AND karyawan_id=".$ey['karyawan_id']
		;
		$result1 = my_query($query);	
		$gajis = my_fetch_array($result1);
		if(	$gajis ){
			$row[] = array(
				'#'=>position_text_align($i,'center'),
				'nik'=>  '\'' .sprintf('%07d',$karyawan['nik']) ,
				'nama'=>  $karyawan['nama_gelar'] ,
			//	'norek'=>  $karyawan['norek'] ,
				'amount'=>  $gajis['gaji_dibayar'] 
			);
		}		

	}
	
	$datas = table_rows_excel($row); 
	return table_builder_excel($header , $datas , 6 ,false ); 
}